

//定义变量
v={
    console:$(".console"),
    pubTimeDisplay:$(".pubTime input"),
    colorCode:$(".colorCode"),
    timeAjax:$(".timeAjax"),
    changeTime:$(".changeTime"),
}






//更新时间
function updateTime(){
    var currentTime="";
    function getTime(){
        var date = new Date();
        var Day = date.getDate()>9?date.getDate():"0"+date.getDate();
        var Year = date.getFullYear();
        var Mouth = date.getMonth()>=9?date.getMonth()+1:"0"+(date.getMonth()+1);
        var hour=date.getHours()>9?date.getHours():"0"+date.getHours();
        var min=date.getMinutes()>9?date.getMinutes():"0"+date.getMinutes();
        var xx=hour>12?"下午":"上午";
        currentTime=Year+"/"+Mouth+"/"+Day+" "+ xx +" "+hour+":"+min;
        $(".headerDate span").html(currentTime);
    };
    getTime();
    setInterval("getTime()",60000)
}


//                  预警信息显示


var forecast={
    forecastArr:[],
    valueLevel:["较低","一般","较高 ！","很高 ！","极高 !"],
    geologyArea(){
        var that=this;
        $.ajax({
            type:"get",
            url:"/micaps/geologyArea",
            success:function(data){

                that.forecastArr=data.concat();
                // 显示街道
                for(var k=0;k<forecast.forecastArr.length;k++){
                    boundary.brr[k]=`萧山区_${forecast.forecastArr[k].split(",")[2]}`;
                    boundary.pic(boundary.brr[k],"red");
                }
            }
        })
    },
    geologyHour(url,num,STR){
        var that=this;
        $.ajax({
            type:"get",
            url:"/micaps/geology"+url,
            success:function(data){
                var str="在未来"+num+"小时";
                for(var i=0;i<data.length;i++){
                    var obj=data[i];
                    for(var j=0;j<that.forecastArr.length;j++){
                        if(obj.areaName==that.forecastArr[j]&&(obj.fileName.slice(obj.fileName.length-3)==STR)){
                            str+=`<span>${obj.areaName.split(",")[2]}</span>的灾害风险<span>${that.valueLevel[obj.value]}</span> `;
                        }
                    }

                }
                $(".slide p").html("此时点暂无灾害风险");
            }
        })
    }
};
function forecastDisplay(){
    forecast.geologyArea();
    forecast.geologyHour("Twelve","十二","001");
    $("#select").change(function(){
        var hour=$(this).val();
        var num=(parseInt(hour)*3).toString();
        hour="00"+hour;
        console.log(num);
        forecast.geologyHour("Three",num,hour);
    });
}
forecastDisplay();





//     绘制地图边界

var map = QXMap.Map('container', {
    zoom:10,
    center: [120.570,30.126],
    maptype: QMAP_NORMAL_MAP
});

var boundary={
    arr:["萧山区_临江街道","萧山区_临浦镇","萧山区_义桥镇","萧山区_义蓬街道","萧山区_党山镇","萧山区_党湾镇","萧山区_前进街道","萧山区_北干街道","萧山区_南阳街道","萧山区_坎山镇","萧山区_城厢街道","萧山区_宁围镇","萧山区_戴村镇","萧山区_所前镇","萧山区_新塘街道","萧山区_新湾街道","萧山区_新街镇","萧山区_河上镇","萧山区_河庄街道",
        "萧山区_浦阳镇","萧山区_益农镇","萧山区_围垦区","萧山区_衙前镇","萧山区_进化镇","萧山区_闻堰镇","萧山区_靖江街道","萧山区_顺坝垦区"],
    brr:[],
    pic(url,color){
        var that=this;
        $.ajax({
            url:"/assets/data/"+url+".xml",
            data:"json",
            success:function(data){
                var points=$(data).find("Area").attr("Coords").split(",");
                for(var i=0,arr=[];i<points.length;i++){
                    if(i%2==0){
                        arr.push({lng:points[i],lat:points[i+1]})
                    }
                }
                var polylineOptions =
                    {
                        color: color,
                        weight: 2,
                        fillColor: 'transparent',
                        opacity: 0.7,
                        fillopacity: 0.8,
                        isfill: true,

                    }
                var polyline = QXMap.PolyLine(arr, polylineOptions,function(){
                    var name=$(data).find("Area").attr("Id");
                    that.click(name);

                });
                map.addVectorLayer(polyline);
                var path=$(".qxmap-overlay-pane svg g").each(function(){
                    if($(this).children().first().attr("stroke-opacity")==0.7){
                        $(this).hover(function(){
                            $(this).children().first().attr("fill","red");
                        },function(){
                            $(this).children().first().attr("fill","transparent")
                        })
                    }
                })

            },
            error:function(){
                console.log("加载失败")
            }
        })
    },
    click(name){
        console.log(name)
        getNameData(name)

    }
}

function getNameData(name) {
  $.ajax({
    type:"get",
    url:"/process/getInfos",
    data:{name:name},
    success:function(data){
        console.log(data)
      var html="";
      for(var i=0;i<data.content.length;i++){
        var obj=data.content[i];
        html+=`<table>
                       <tr>
                           <td>乡镇名称：</td>
                           <td>${obj.xsAreaName}</td>
                       </tr>
                       <tr>
                           <td>灾害名称：</td>
                           <td>${obj.disasterTypeName}</td>
                       </tr>
                       <tr>
                           <td>子类名称:</td>
                           <td>${obj.disasterSubtypeName}</td>
                       </tr>
                       <tr>
                           <td>灾害强度：</td>
                           <td>${obj.strengthLevel}</td>
                       </tr>
                       <tr>
                           <td>起始时间：</td>
                           <td>${obj.startTime}</td>
                       </tr>
                       <tr>
                           <td>结束时间：</td>
                           <td>${obj.endTime}</td>
                       </tr>
                       <tr class="high">
                           <td>致灾原因：</td>
                           <td>${obj.causes}</td>
                       </tr>
                       <tr class="high">
                           <td>后期影响：</td>
                           <td>${obj.laterInfluence}</td>
                       </tr>
                       <tr class="high">
                           <td>灾情描述：</td>
                           <td>${obj.description}</td>
                       </tr>
                   </table>`;
      }
      $(".clickContent").html(html);
      $(".clickXs").removeClass("displayNone");
    }
  })

}

for(var i=0;i<boundary.arr.length;i++){
    boundary.pic(boundary.arr[i],"blue");
}//瓜沥镇、蜀山街道有问题

getNameData("南阳街道")
